/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rpg.gameSkeleton;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import rpg.Dungeon;
import rpg.PlayerCharacter;
import rpg.controller.HeroCollisionManager;
import rpg.tools.FileManager;
import rpg.controller.HeroCollisionManager;

/**
 *
 * @author Emmanouil Samatas
 */
public class GameFrame extends JFrame implements BattleObserver {

    private final int MAP_STATE = 0;
    private final int BATTLE_STATE = 1;
    private int state;
    private FileManager loader = FileManager.getInstance();
    private PlayerCharacter pc = new PlayerCharacter();
    private Dungeon dungeon = new Dungeon(4);
    private HeroCollisionManager heroController = new HeroCollisionManager(pc, dungeon);
    Board myBoard = new Board(dungeon, pc, heroController);

    public GameFrame() {


        add(myBoard);
        setTitle("Diablo 4");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
       
        setVisible(true);
        this.setSize(700, 460);

    }

    public void register() {
        heroController.registerObserver(this);
    }

    @Override
    public void battleBegins() {
        this.setFocusableWindowState(false);
        this.setFocusable(false);
        BattleFrame bf = new BattleFrame(pc);
        bf.registerToBattleObserver(this);


    }

    public static void main(String[] args) {

        GameFrame gf = new GameFrame();
        gf.register();
    }

    @Override
    public void battleEnded(boolean playerWon) {
        setFocusableWindowState(true);
        setVisible(true);
        if(playerWon){
        dungeon.setMapPoint(pc.getX(), pc.getY(), 'o');
        }
        else{
            
            JOptionPane.showMessageDialog(rootPane,"GAME OVER");
            System.exit(0);
        }
    }

}
